clear;
close all;
clc;
test_tic = tic;
YearMonthDay = 20191018;
Photo_Start = 590;
Photo_End = 591;
trunc = 52000;

Bad_Pics_All = {};
Puter_Name = getenv('computername');
if strcmp(Puter_Name, 'CALCENTER2')
    Puter_Name_Pre = 'D:\';
    refimagesIniDirectory = [Puter_Name_Pre 'Rb87ProgramBEC3\removeBackground\backgrounddata\refimagesIni_22834new.mat'];
elseif strcmp(Puter_Name, 'WEI-PC')
    Puter_Name_Pre = 'F:\';
    refimagesIniDirectory = [Puter_Name_Pre 'Rb87ProgramBEC3\removeBackground\backgrounddata\refimagesIni_22834new.mat'];
elseif strcmp(Puter_Name, '') && strcmp(getenv('USERNAME'), 'rb87bec3')
    refimagesIniDirectory = '/media/rb87bec3/Files/vc/Rb87ProgramBEC3/removeBackground/backgrounddata/refimagesIni_22834new.mat';
end

% folderName=['\\rb87bec2\DataBackup\' num2str(YearMonthDay) 'morning\ikon-22834\'];
% folderName=['\\rb87bec2\ShareFolder\' num2str(YearMonthDay) 'morning\ikon-22834\'];

% RemoteName = '//192.168.1.25/ShareFolder';
% MountName = '/mnt/rb87bec2/ShareFolder';
% folderName = ['/mnt/rb87bec2/ShareFolder/' num2str(YearMonthDay) 'morning/ikon-22834/'];

RemoteName = '//192.168.1.25/Databackup2';
MountName = '/mnt/rb87bec2/Databackup2';
folderName = ['/mnt/rb87bec2/Databackup2/' num2str(YearMonthDay) 'morning/ikon-22834/'];
if isfolder(folderName) == 0
    system(['mount -t cifs -o username=rb87bec3,password=. ' RemoteName ' ' MountName])
end
% Save_Folder_Name = ['D:\oriData\' num2str(YearMonthDay) 'New_Method\'];
Save_Folder_Name = ['/media/rb87bec3/Files/oriData/' num2str(YearMonthDay) 'New_Method/'];
while(1)
    if Photo_Start > Photo_End
        break
    end
    disp(['Start with photo ' num2str(Photo_Start)]);
    [photoInd,refimagesIni,Bad_Pics] = RemoveBGNew(Photo_Start,Photo_End,YearMonthDay,trunc,folderName,Save_Folder_Name);
    Bad_Pics_All = [Bad_Pics_All Bad_Pics];
    Photo_Start = photoInd;
    save(refimagesIniDirectory,'refimagesIni');
    
end
toc(test_tic)